<?php
class b2c_ctl_admin_business_orderlist extends desktop_controller{
	public function __construct($app)
    {
        parent::__construct($app);
		header("cache-control: no-store, no-cache, must-revalidate");
    }

	public function index(){
		//if($_GET['action'] == 'export') $this->_end_message = '导出订单';
		$this->finder('b2c_mdl_business_orders',array(
				'title'=>app::get('b2c')->_('供应商列表'),
				//'use_buildin_export'=>true,//导出
				'use_buildin_recycle'=>false,//删除
				'use_buildin_filter'=>false,//高级筛选
				'object_method'=>array('count' => 'get_finder_count', 'getlist' => 'get_finder'),
		));
	}

	/**
	 * 供应商订单view 列表
	 * @param null
	 * @return null
	 */
	public function _views(){
		$mdl_delivery = $this->app->model('business_orders');
		$sub_menu = array(
				0=>array('label'=>app::get('b2c')->_('未确认'),'optional'=>false,'filter'=>array('status'=>array('0','2'),'order_status|noequal'=>'dead')),
				1=>array('label'=>app::get('b2c')->_('已确认'),'optional'=>false,'filter'=>array('status'=>'1')),
		);

		if(isset($_GET['optional_view'])) $sub_menu[$_GET['optional_view']]['optional'] = false;

		foreach($sub_menu as $k=>$v){
			if($v['optional']==false){
				$show_menu[$k] = $v;
				if(is_array($v['filter'])){
					$v['filter'] = array_merge(array(),$v['filter']);
				}else{
					$v['filter'] = array();
				}
				$show_menu[$k]['filter'] = $v['filter']?$v['filter']:null;
				if($k==$_GET['view']){
					$show_menu[$k]['newcount'] = true;
					$show_menu[$k]['addon'] = $mdl_delivery->get_finder_count();
				}
				$show_menu[$k]['href'] = 'index.php?app=b2c&ctl=admin_business_orderlist&act=index&view='.($k).(isset($_GET['optional_view'])?'&optional_view='.$_GET['optional_view'].'&view_from=dashboard':'');
			}elseif(($_GET['view_from']=='dashboard')&&$k==$_GET['view']){
				$show_menu[$k] = $v;
			}
		}
		return $show_menu;
	}

	//根据供应商查找  by liuyulei 2016/10/22
	function to_split(){
		$page = $_GET['page']?$_GET['page']:1;
		$limit_end = 20;
		$limit_start = ($page-1)*$limit_end;
		$limit = ' limit '.$limit_start.','.$limit_end;

		$objOrder = $this->app->model('business_orders_objects');

		if(isset($_GET['order'])) {
			if ($_GET['order']=='timeup') {
				$order =  'createtime asc';
			} else if($_GET['order']=='timedown') {
				$order =  'createtime desc';
			}else if($_GET['order']=='bnup') {
				$order =  'bn asc';
			}else if($_GET['order']=='bndown') {
				$order =  'bn desc';
			}
			if($_GET['state'] == 0) {
				$info = $objOrder->get_business_order_objects_order($_GET['business_id'], $_GET['state'], $order);
			}else{
				$info = $objOrder->get_business_order_objects_order($_GET['business_id'], $_GET['state'], $order, $limit);
			}
		}else{
			if ($_GET['state'] == 0) {
				$info = $objOrder->get_business_order_objects($_GET['business_id']);
			} else {
				$info = $objOrder->gethas_business_order_objects($_GET['business_id'], $limit);
			}
		}

		//echo '<pre>';print_r($info);die();
		$this->pagedata['info'] = $info;
		$this->pagedata['business_id'] = $_GET['business_id'];
		$this->pagedata['state'] = $_GET['state'];
		$this->display('admin/business/business_orderslist.html');
	}

}